<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <title>Title</title>

  <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
  <link rel="stylesheet" href="../layuimini/js/lay-module/dtree/dtree.css">
  <link rel="stylesheet" href="../layuimini/js/lay-module/dtree/font/dtreefont.css">
</head>
<body class="layuimini-container">
<div class="layuimini-main">



  <div id="tree1" data-id="0"></div>



  <button class="layui-btn" onclick="changePermission()">确认修改</button>
</div>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../layuimini/js/lay-config.js" charset="utf-8"></script>
<script th:inline="javascript">
  var dtree;
  var $;
  var rid = [[${rid}]];
  function changePermission(){
    //获取所有复选框选中的节点
    const data = dtree.getCheckbarJsonArrParam("tree1");
    console.log(data);
    //所有选中节点的id
    const ids = data.nodeId;
    const d = {rid: rid, ids: ids};
    $.post('/permission/change',d,function (res){
      if (res.code === 0) {
        var iframeIndex = parent.layer.getFrameIndex(window.name);
        parent.layer.close(iframeIndex);
        parent.layer.msg(res.msg);
      }
    })
  }

  layui.use(["tree","dtree"],function (){
    console.log(rid);
    // var tree = layui.tree;
    $ = layui.jquery;
    dtree = layui.dtree;

    dtree.render({
      line: false,
      skin: "layui",
      elem: "#tree1",
      url: "/permission/role/"+rid,
      async: false,
      checkbar: true
    });

  });
</script>
</body>
</html>
